<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务，帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件，不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types = 1);

namespace app\common\model\ding;

use cores\BaseModel;

/**
 * 文章模型
 * Class Article
 * @package app\common\model
 */
class Seat extends BaseModel {
	// 定义表名
	protected $name = 'ding_seat';

	// 定义主键
	protected $pk = 'seat_id';

	/**
	 * 追加字段
	 * @var array
	 */
	protected $append = ['status_text'];
	public function getStatusTextAttr($value, $data) {
		switch ($data['status']) {
		case 30:
			$status = '预订';
			break;
		case 40:
			$status = '用餐';
			break;

		case 50:
			$status = '禁用';
			break;

		default:
			$status = '空闲';
			break;
		}
		return $status;
	}

	public function image() {
		$module = self::getCalledModule();
		return $this->hasOne("app\\{$module}\\model\\UploadFile", 'file_id', 'image_id')->bind(['image_url' => 'preview_url']);

	}
	public function images() {
		$module = self::getCalledModule();
		return $this->hasMany("SeatImages", 'seat_id', 'seat_id');

	}
	public function tags() {
		return $this->hasMany('SeatTag', 'seat_id', 'seat_id');

	}
	public function shop() {
		$module = self::getCalledModule();
		return $this->hasOne("app\\{$module}\\model\\store\\Shop", 'shop_id', 'shop_id')->bind(['shop_name' => 'shop_name']);

	}
	/**
	 * 文章详情
	 * @param int $articleId
	 * @param array $with
	 * @return array|null|static
	 */
	public static function detail(int $articleId, array $with = []) {
		return self::get($articleId, $with);
	}
}
